Skip to content

Feat/wasm opt post build#238

Merged
0xGeorgii merged 3 commits into
mainfrom
feat/wasm-opt-post-build
Jul 3, 2026
Merged

Feat/wasm opt post build#238
0xGeorgii merged 3 commits into
mainfrom
feat/wasm-opt-post-build

Conversation

@0xGeorgii

@0xGeorgii 0xGeorgii commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

Safe to merge — the change is entirely additive, the default pipeline is byte-identical when no [build.wasm-opt] table is present, and every failure path leaves the original out/main.wasm untouched.

All new code paths are guarded by explicit opt-in (manifest table presence), failure cases are handled defensively (atomic rename, temp cleanup, re-validation), and the test suite includes hermetic unit tests, a compiled fake-binary fixture, and in-process TCP stub integration tests covering the full install-and-optimize lifecycle. The one noted inconsistency — a fixed rather than process-unique temp file in the optimizer — is a minor concern that does not affect correctness for typical usage.

apps/infs/src/commands/wasm_opt.rs — the optimized_tmp_path helper uses a fixed sibling name (main.wasm.opt) rather than a process-unique one; see inline comment.

Important Files Changed

Filename Overview
apps/infs/src/commands/wasm_opt.rs New module: post-build optimization driver. Verification-opcode pre-scan, three-tier wasm-opt resolution, version check, atomic rename via sibling temp file, re-validation, doctor check, and full unit test suite. The temp file name is fixed rather than process-unique (see comment).
apps/infs/src/toolchain/binaryen.rs New module: pinned Binaryen provisioning. Idempotent, atomic install with SHA-256 verification, macOS dylib handling, SHA test seam tied to base-URL override (security property), and comprehensive unit tests.
apps/infs/src/commands/component.rs New module: infs component add
apps/infs/src/project/manifest.rs Adds WasmOptConfig struct with serde deserialization, level validation against WASM_OPT_LEVELS, and BuildConfig::is_default() updated to account for the wasm-opt sub-table presence; round-trip serialization tested.
apps/infs/src/commands/project_build.rs Adds no_wasm_opt parameter to run_project_build and calls post_build_optimize after a successful infc exit; clean integration point with no existing logic changed.
apps/infs/tests/cli_integration.rs ~1550 lines of new integration tests covering the full wasm-opt and component lifecycle: hermetic fake binary via a compiled fixture, in-process TCP stub for network isolation, concurrent-safe by env-var injection rather than PATH mutation.
apps/infs/tests/fixtures/fake_wasm_opt.rs Dependency-free fake wasm-opt fixture compiled at test time; handles --version probe, invocation logging, controlled exit code, and garbage-output injection — covers all four error paths in optimize_in_place.
editors/vscode/src/commands/installComponent.ts New VS Code command: guards against concurrent installs with a module-level flag, validates component name against KNOWN_COMPONENTS, surfaces install/retry error actions, and triggers a doctor refresh on success.
editors/vscode/src/commands/doctor.ts Doctor command gains an Install wasm-opt action button on both error and warning notifications when wasmOptNeedsAttention() is true; delegates to inference.installComponent.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[infs build / infs run] --> B{project mode?}
    B -- no --> Z[single-file: unchanged pipeline]
    B -- yes --> C[run infc compile]
    C --> D{infc exit 0?}
    D -- no --> E[error: build failed]
    D -- yes --> F{wasm-opt table present and enabled and not --no-wasm-opt?}
    F -- no --> G[out/main.wasm as-is]
    F -- yes --> H{proof mode or -v build?}
    H -- yes --> I[skip silently]
    H -- no --> J[read out/main.wasm]
    J --> K{verification opcode in bytes?}
    K -- yes --> L[hard error: name construct plus remediation]
    K -- no --> M{resolve wasm-opt: WASM_OPT_PATH then PATH then managed?}
    M -- found --> N[check version >= 116]
    M -- not found, auto-install=true --> O[download plus verify SHA-256]
    M -- not found, auto-install=false --> P[hard error: install hints]
    O --> N
    N --> Q[wasm-opt runs, writes main.wasm.opt]
    Q --> R{exit 0?}
    R -- no --> S[error: leave original unchanged]
    R -- yes --> T[re-validate optimized bytes]
    T --> U{valid?}
    U -- no --> V[error: leave original unchanged]
    U -- yes --> W[atomic rename to out/main.wasm, print size summary]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[infs build / infs run] --> B{project mode?}
    B -- no --> Z[single-file: unchanged pipeline]
    B -- yes --> C[run infc compile]
    C --> D{infc exit 0?}
    D -- no --> E[error: build failed]
    D -- yes --> F{wasm-opt table present and enabled and not --no-wasm-opt?}
    F -- no --> G[out/main.wasm as-is]
    F -- yes --> H{proof mode or -v build?}
    H -- yes --> I[skip silently]
    H -- no --> J[read out/main.wasm]
    J --> K{verification opcode in bytes?}
    K -- yes --> L[hard error: name construct plus remediation]
    K -- no --> M{resolve wasm-opt: WASM_OPT_PATH then PATH then managed?}
    M -- found --> N[check version >= 116]
    M -- not found, auto-install=true --> O[download plus verify SHA-256]
    M -- not found, auto-install=false --> P[hard error: install hints]
    O --> N
    N --> Q[wasm-opt runs, writes main.wasm.opt]
    Q --> R{exit 0?}
    R -- no --> S[error: leave original unchanged]
    R -- yes --> T[re-validate optimized bytes]
    T --> U{valid?}
    U -- no --> V[error: leave original unchanged]
    U -- yes --> W[atomic rename to out/main.wasm, print size summary]
Loading

Reviews (2): Last reviewed commit: "Update component.rs" | Re-trigger Greptile

@0xGeorgii 0xGeorgii self-assigned this Jul 3, 2026
@0xGeorgii 0xGeorgii added enhancement New feature or request codegen Bytecode emitting vscode VSCode extension performance Memory / CPU labels Jul 3, 2026
@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Comment thread apps/infs/src/commands/component.rs
Comment thread apps/infs/src/commands/component.rs
@0xGeorgii 0xGeorgii merged commit 8b902d9 into main Jul 3, 2026
7 checks passed
@0xGeorgii 0xGeorgii deleted the feat/wasm-opt-post-build branch July 3, 2026 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codegen Bytecode emitting enhancement New feature or request performance Memory / CPU vscode VSCode extension

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant